home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Development / 3DMF parser / 0.9 version / MFMEMORY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-21  |  1.5 KB  |  80 lines  |  [TEXT/MPS ]

  1. /*==============================================================================
  2.  *
  3.  *    File:        MFMEMORY.C
  4.  *
  5.  *    Function:    Memory allocation routines
  6.  *
  7.  *    Author(s):    Rick Wong (RWW)
  8.  *
  9.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  10.  *
  11.  *    Change History (most recent first):
  12.  *        Fabio    Changed file name to 8 characters
  13.  *        F3L_RWW    File created.
  14.  *==============================================================================
  15.  */
  16. #define MF3D_MEMORY_C
  17. #include "MFMEMORY.H"
  18. #undef MF3D_MEMORY_C
  19.  
  20. #include <stdlib.h>
  21.  
  22. #include "MFASSERT.H"
  23.  
  24. void *
  25. MF3D_Malloc(
  26.     size_t    size)
  27. {
  28. #if defined(DEBUG) && DEBUG > 1
  29.     void *tempPtr;
  30.  
  31.     tempPtr = malloc(size);
  32.     printf("%d: malloc(%lx)\n", ++gMallocCount, tempPtr);
  33.     return tempPtr;
  34. #else
  35.     return malloc(size);
  36. #endif
  37. }
  38.  
  39. #include <types.h>
  40. void *
  41. MF3D_Realloc(
  42.     void *    ptr,
  43.     size_t    size)
  44. {
  45. #if defined(DEBUG) && DEBUG > 1
  46.     void *tempPtr;
  47.  
  48.     /* The C manual does not seem to explicitly state that
  49.      * realloc(NULL, size) is equivalent to malloc(size).
  50.      * So, to make sure we do not fail with some compiler somewhere,
  51.      * we will always malloc before realloc.
  52.      */
  53.     MFASSERT(ptr != NULL);
  54.     MFASSERT(size > 0);
  55.     tempPtr = realloc(ptr, size);
  56.     if (tempPtr != ptr)
  57.     {    if (ptr == NULL)
  58.             ++gMallocCount;
  59.         printf("%d: realloc(%lx to %lx)\n", gMallocCount, ptr, tempPtr);
  60.     }
  61.     return tempPtr;
  62. #else
  63.     return realloc(ptr, size);
  64. #endif
  65. }
  66.  
  67. void
  68. MF3D_Free(
  69.     void *    ptr)
  70. {
  71. #if defined(DEBUG) && DEBUG > 1
  72.     free(ptr);
  73.     if (ptr != NULL)
  74.     {    printf("%d: free(%lx)\n", --gMallocCount, ptr);
  75.     }
  76. #else
  77.     free(ptr);
  78. #endif
  79. }
  80.